﻿/***********************************************************************************************
 * 
 * ProjectName: WMSSoft.Lib.Interfaces
 * 
 * Description: Provide the Interface to describe a Function used on WinKStart
 * 
 * Created:     12.09.2014
 * 
 * Author:      matthias wagler - matthias@WMSSoft.de
 * 
 * Copyright:   Copyright 2014 by WMSSoft.de
 * 
 * License:     GPLv3
 * 
 * History:     12.09.2014 - matthias wagler matthias@WMSSoft.de   -   Created
 * 
 **********************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMSSoft.Lib.Enums;
using WMSSoft.Lib.Interfaces;
using WMSSoft.Lib.WinKStart;

namespace WMSSoft.WinKStart.Functions
{
    public class AddFavorites : iWinKStartFunctions
    {

        #region Interface Members
        /// <summary>
        /// Interface Member to Initialise the Function
        /// </summary>
        public void Init()
        {
            //Nothing TODO
        }

        /// <summary>
        /// Run the Code for this WinKStart Function
        /// </summary>
        /// <param name="DataSource">DataSource to work with Data from</param>
        /// <param name="Filter">Path to specify the Sub - Folder in DataSource</param>
        /// <param name="Data">Data from GUI to work with</param>
        /// <returns></returns>
        public bool Run(Dictionary<string, object> Data)
        {
            try
            {
                cFavoritenReader tmpFavoritenReader = new cFavoritenReader();
                tmpFavoritenReader.LoadFromDisk();
                if (Data.ContainsKey("ContentType") == true)
                {
                    switch ((eContentPanelContentType)Data["ContentType"])
                    {
                        case eContentPanelContentType.Programs:
                            if (Data.ContainsKey("ItemName") == true)
                                tmpFavoritenReader.AddFavorite((string)Data["ItemName"]);
                            break;
                        case eContentPanelContentType.RecentOpenedDocuments:
                            if (Data.ContainsKey("ItemName") == true)
                                tmpFavoritenReader.AddFavoriteDocument((string)Data["ItemName"]);
                            break;
                        case eContentPanelContentType.System:
                            if (Data.ContainsKey("FolderPath") == true && Data.ContainsKey("LinkFilename") == true &&
                                Data.ContainsKey("ViewName") == true && Data.ContainsKey("Arguments") == true)
                            {
                                string sFullPathName = "";
                                if (Data["FolderPath"] != null && Data["LinkFilename"] != null && 
                                    ((string)Data["FolderPath"]).Length > 0 && ((string)Data["LinkFilename"]).Length > 0)
                                    sFullPathName = System.IO.Path.Combine((string)Data["FolderPath"], (string)Data["LinkFilename"]);

                                string stmpArguments = "";
                                string stmpViewName = "";
                                if (Data["Arguments"] != null)
                                    stmpArguments = (string)Data["Arguments"];

                                if (Data["ViewName"] != null)
                                    stmpViewName = (string)Data["ViewName"];

                                if (sFullPathName.Length > 0)
                                    tmpFavoritenReader.AddFavorite(sFullPathName, stmpArguments, stmpViewName, false);
                            }
                            break;
                    }
                    tmpFavoritenReader.SaveToDisk();
                    //if (Data["ContentType"] == eContentPanelContentType.Programs
                }
                return true;
            }
            catch (Exception Ex)
            {
                throw new Exception("Error running Function!", Ex);                
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void Destroy()
        {
            //Nothing TODO
        }

        #endregion


    }


}
